# 中序遍历



class Solution:

    def kthSmallest(self, root, k):
        self.ans = 0
        def dfs(root):  

            # nonlocal ans
            if not root:
                return
            
            dfs(root.left)
            if self.k == 0:
                return

            self.k -= 1
            if self.k == 0:
                self.ans = root.val

            dfs(root.right)
        

        self.k = k
        dfs(root)
        return self.ans



